using System;
using System.Windows.Forms;

namespace ImpEx.GUI
{
    public partial class ConsoleForm : Form
    {
        private static ConsoleForm _console;
        private static object _lock = new object();

        public ConsoleForm()
        {
            InitializeComponent();
        }

        public static ConsoleForm Instance
        {
            get
            {
                lock (_lock)
                {
                    if (_console == null || _console.IsDisposed)
                    {
                        _console = new ConsoleForm();
                        _console.Visible = true;
                    }
                    return _console;
                }
            }
        }

        public static void ConsoleOutput(string line)
        {
            ConsoleForm console = Instance;

            console.Invoke(new FormCallback(delegate
            {
                console.InfoTextBox.AppendText(line);
                console.InfoTextBox.AppendText("\r\n");
                //console.InfoTextBox.ScrollToCaret();
            }));
        }

        private void LoadingForm_Load(object sender, EventArgs e)
        {
            InfoTextBox.Clear();
        }
    }
}